from orm.user import User
from orm.attend import Attend
from config import db
from datetime import datetime
import random
if __name__ == '__main__':
    db.connect()
    db.create_tables([User, Attend])
    user = User.create(name='Test', password='Test')
    print(user.uid)
    for i in range(15):
        y = 2019
        m = 6
        d = 1 + i
        h1 = 8
        h2 = 16
        m1 = random.randint(0, 59)
        m2 = random.randint(0, 59)
        date1 = datetime(y, m, d, h1, m1, 0, 0).timestamp()
        date2 = datetime(y, m, d, h2, m2, 0, 0).timestamp()
        is_fine = False
        if date2 - date1 > 3600 * 8:
            is_fine = True
        Attend.create(uid=str(user.uid), date=datetime(y, m, d), on_date=date1, off_date=date2, is_fine=is_fine)
    attend = Attend.select()
    for a in attend:
        print(a.uid, a.date, a.on_date, a.off_date, a.is_fine)
    db.close()
